<?php

abstract class Base_App extends Base_Base
{
    public function __construct()
    {
        $this->_call();
        echo $this->View($this->Path);
    }
    final public function _call(Base_Path $pathArgs = NULL)
    {
        $methodName = $this->Path[0];
        if (is_null($pathArgs)) $pathArgs = clone $this->Path;
        if (!empty($methodName) && method_exists($this, $methodName) && $this->_hasVisibleMethod($methodName) && $methodName != 'index') {
            if (!empty($pathArgs[1]) && method_exists($this, $newMethodName = $methodName.ucfirst($pathArgs[1]))) {
            	//Rebuilds the Path Arguments
            	$pathArgs[0] = $newMethodName;
            	unset($pathArgs[1]);
            	$this->Path[0] = $newMethodName;
            	unset($this->Path[1]);
                //Call the fresh new method
                return $this->_call($pathArgs);
            } else {
            	//Remove old arguments
                unset($pathArgs[0]);
                //Call the method
                return call_user_func_array(array($this, $methodName), 
                
                    //Due to a php bug, you MUST call this way
                    $pathArgs->_path);
            }
        //The method has problems, call index instead
        } else {
            return call_user_func_array(array($this, 'index'), 
            
                //Due to a php bug, you MUST call this way
                $pathArgs->_path);
        }
    }
    static public function smartFactory($between, $path = 0)
    {
    	//Choose the name of the new application
        $appName = Base_Path::_chooseAppName($between,$path);
        return new $appName($path);
    }
    public function index()
    {
        print_r(func_get_args());
        //Does absolutely nothing here. Please extend this!
    }
}

?>
